<!doctype html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="Origin" content="http://s.bolq.com/okFjl1">
  <title>天天打波利互点工具</title>
  <script>
  function start() {
    // Parse links from the textarea
    var links = [];
    var linkstext = O("linkstext");
    var texts = linkstext.value.split(/\r|\n/);
    for(var i=0; i<texts.length; i++) {
      var str = texts[i].trim();
      if (str.startsWith("http:")) {
        links.push(str);
      }
    }
    // Create <a> for each link
    var as = [];
    var myframe = O("myframe");
    var linksdiv = O("linksdiv");
    linksdiv.innerHTML = "";
    for(var i=0; i < links.length; i++) {
      var link = links[i];
      var a = E("a"); as.push(a);
      a.href= 'javascript:;';
      a.onclick = (function (xlink){
        return function() {
          myframe.src=xlink;
          if (!this.innerHTML.startsWith(" * "))this.innerHTML = " * " + this.innerHTML;
          //this.style="background-color:#007;color:white";
        }
      })(link);
      a.innerHTML = (i+1) + ": " + link;
      linksdiv.appendChild(a);
      linksdiv.appendChild(E("br"));
    } //for(...)
    // Auto click next <a> after loaded
    var i = 0;
    myframe.onload = function() {
      console.log("hei hei hei: " + myframe.src);
      //if (++i < as.length) as[i].click();
    } //myframe.onload
    // Auto start to click the first link
    if (as.length > 0) as[0].click();
  } //function start()
  function E(name) { return document.createElement(name); }
  function O(id) { return document.getElementById(id); }
  </script>
</head>
<body>
  <div><textarea id="linkstext"></textarea><button onclick="start()">开始点！</button></div>
  <div id="linksdiv" style="float:left"> </div>
  <iframe id="myframe" style="float:left; width:300px; height:500px"></iframe>
</body>
</html>
